<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="author" content="得闲技术 Team">
    <meta name="copyright" content="得闲技术">
    <title>添加管理员 - Powered By 得闲技术</title>
    [#include "/admin/main/resources/list.ftl"/]
</head>
<body class="admin secondary">
<main>
    <div class="container-fluid">
        <form id="saveOrUpdateForm" class="ajax-form form-horizontal" action="save" method="post">
            <div class="panel panel-default">
                <div class="panel-heading">添加管理员</div>
                <div class="panel-body padding-5">

                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#basic" data-toggle="tab">基本信息</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div id="basic" class="tab-pane active">

                            <div class="form-group">
                                <label class="col-xs-3 col-sm-2 control-label item-required" for="role">角色:</label>
                                <div class="col-xs-9 col-sm-4">
                                    [#list roles as role]
                                        <div class="checkbox checkbox-inline" title="${role.description!}"
                                                data-toggle="tooltip">
                                            <input id="roleIds_${role_index}" name="roleIds" type="checkbox"
                                                    value="${role.id}" required="required">
                                            <label for="roleIds_${role_index}">${role.name!}</label>
                                        </div>
                                    [/#list]
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-xs-3 col-sm-2 control-label item-required" for="departmentId">部门:</label>
                                <div class="col-xs-9 col-sm-4">
                                    <select name="departmentId" id="departmentId" class="selectpicker form-control"
                                            data-live-search="true" required="required">
                                        [#list departments as department]
                                            <option value="${department.id}" [#if !department.isEnabled]disabled="disabled"[/#if]>
                                                [#if department.grade != 0]
                                                    [#list 1..department.grade as i]
                                                        &nbsp;&nbsp;
                                                    [/#list]
                                                [/#if]
                                                ${department.name}
                                            </option>
                                        [/#list]
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-xs-3 col-sm-2 control-label item-required" for="name">姓名:</label>
                                <div class="col-xs-9 col-sm-4" title="仅允许中文和下划线的组合哦，如果名字中包含“·”，请使用下划线代替"
                                        data-toggle="tooltip">
                                    <input id="name" name="name" class="form-control" type="text" minlength="2"
                                            maxlength="20"
                                            required="required" />
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-xs-3 col-sm-2 control-label item-required" for="username">用户名:</label>
                                <div class="col-xs-9 col-sm-4" title="仅允许数字、英文、中文和下划线的组合" data-toggle="tooltip">
                                    <input id="username" name="username" class="form-control" type="text" minlength="2"
                                            maxlength="20" required="required" />
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-xs-3 col-sm-2 control-label item-required" for="mobile">手机号码:</label>
                                <div class="col-xs-9 col-sm-4" title="用于接收短信验证码以及一些安全风险信息" data-toggle="tooltip">
                                    <input id="mobile" name="mobile" class="form-control" type="text" digits="true"
                                            minlength="11" maxlength="11"
                                            required="required" />
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-xs-3 col-sm-2 control-label item-required" for="password">密码:</label>
                                <div class="col-xs-9 col-sm-4">
                                    <input id="password" name="password" class="form-control" type="password"
                                            minlength="6" maxlength="60"
                                            required="required" />
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-xs-3 col-sm-2 control-label item-required"
                                        for="password">确认密码:</label>
                                <div class="col-xs-9 col-sm-4">
                                    <input id="rePassword" name="rePassword" class="form-control" type="password"
                                            minlength="6" maxlength="60" required="required" />
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-xs-3 col-sm-2 control-label item-required" for="gender">性别:</label>
                                <div class="col-xs-9 col-sm-4">
                                    <select name="gender" id="gender" class="selectpicker form-control" required="required">
                                        [#list gender as g]
                                            <option value="${g}">
                                               ${message("GenderEnum." + g)}
                                            </option>
                                        [/#list]
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-xs-3 col-sm-2 control-label" for="avatar">头像:</label>
                                <div class="col-xs-9 col-sm-4">
                                    <input id="avatar" name="avatar" type="hidden" data-provide="fileinput"
                                            data-file-type="IMAGE" maxlength="500">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-xs-3 col-sm-2 control-label">设置:</label>
                                <div class="col-xs-9 col-sm-4">
                                    <div class="checkbox checkbox-inline">
                                        <input name="_isEnabled" type="hidden" value="false">
                                        <input id="isEnabled" name="isEnabled" type="checkbox" value="true" checked>
                                        <label for="isEnabled">启用</label>
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
                <div class="panel-footer">
                    <div class="row">
                        <div class="col-xs-9 col-sm-10 col-xs-offset-3 col-sm-offset-2">
                            <button class="btn btn-primary" type="submit">确 定</button>
                            <button class="btn btn-default" type="button" data-action="back">返 回</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</main>
<script>
    $().ready(function () {

        var $saveOrUpdateForm = $("#saveOrUpdateForm");

        // 表单验证
        $saveOrUpdateForm.validate({
            rules: {
                name: {
                    required: true,
                    pattern: /^[_\u4e00-\u9fa5]+$/,
                },
                rePassword: {
                    equalTo: "#password"
                },
                username: {
                    pattern: /^[0-9a-zA-Z_\u4e00-\u9fa5]+$/,
                    remote: {
                        url: "check_username",
                        cache: false
                    }
                },
                mobile: {
                    remote: {
                        url: "check_mobile",
                        cache: false
                    }
                }
            },
            messages: {
                name: {
                    pattern: "姓名不符合规范"
                },
                username: {
                    pattern: "用户名不符合规范",
                    remote: "用户名已存在"
                },
                mobile: {
                    remote: "手机号码已存在"
                }
            },
            submitHandler: function (form) {
                $(form).ajaxSubmit();
            }
        });
    });
</script>
</body>
</html>
